Use case: I2C communication in polling mode

This use case shows how to initialize an I2C instance and start a master transmit operation in polling mode.

Note

The API for all communication modes was renamed between HAL1 and HAL2.

Sequence diagram

    @startuml
    participant "Application" as App
    participant "I2C" as I2C

    App -> I2C: HAL_I2C_Init()
    App -> I2C: HAL_I2CEx_ConfigAnalogFilter()
    App -> I2C: HAL_I2C_Master_Transmit()

   @enduml

Code snippet

HAL1

HAL2

/* Add your init and cpnfig */
HAL_I2C_Init(&hi2c);
HAL_I2CEx_ConfigAnalogFilter(&hi2c,
                             I2C_ANALOGFILTER_ENABLE) ;
/* Start a I2C Process */
HAL_I2C_Master_Transmit(&hi2c,
                        DevAddress,
                        &pData,
                        Size,
                        Timeout);
HAL_I2C_Init(&hi2c, HAL_I2C1);
HAL_I2C_SetConfig(&hi2c, &i2c_config);
HAL_I2C_EnableAnalogFilter(&hi2c);
/* Start a I2C Process */
HAL_I2C_MASTER_Transmit(&hi2c,
                        device_addr,
                        &p_data,
                         size_byte,
                         timeout_ms);

Key changes

  1. HAL2 uses renamed I2C APIs (for example, HAL_I2C_MASTER_Transmit() instead of HAL_I2C_Master_Transmit()).

  2. In HAL2, the I2C configuration is applied via HAL_I2C_SetConfig().

  3. In HAL2, the analog filter is enabled via HAL_I2C_EnableAnalogFilter().